﻿using Microsoft.IdentityModel.Tokens;
using netcore_comm.SqlSugar;
using netcore_service.Dto;
using netcore_service.IRepository;
using netcore_service.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace netcore_service.Repositories
{
    public class AdSpaceRepository : SqlSugarRepository<AdSpace, netData>, IAdSpaceRepository
    {
        private readonly ISqlSugarFactory _sqlSugarFactory;
        public AdSpaceRepository(ISqlSugarFactory sqlSugarFactory) : base(sqlSugarFactory)
        {
            _sqlSugarFactory = sqlSugarFactory;
        }

        public async Task<List<AdSpaceDto>> GetAdSpaceByTypeAsync(string type, bool isweixin = false)
        {
            var db = _sqlSugarFactory.GetInstance(nameof(netData));
            var list = await db.Queryable<AdSpace>().
                WhereIF(!string.IsNullOrEmpty(type), e => e.Type == type).
                Where(e => e.IsWeixin == isweixin)
                .Select(e => new AdSpaceDto { address = e.ImageAddress, link = e.Link, id = e.Id }).ToListAsync();
            return list;
        }
    }
}
